<template>
    <div class="app-detail">
        <el-card class="box-card">
            <div class="container-header">
                <div class="hign-line"></div>
                <div class="header-left">
                    {{$t('inventoryManagement.baseInfo')}}
                </div>
            </div>
            <el-form :model="viewModel" ref="passForm" label-width="88px" :rules="rules">
                <el-row :gutter="24" class="mb8">
                    <el-col :span="24">
                        <el-table stripe ref="passTable" :data="passModel">
                            <el-table-column :label="$t('inventoryManagement.supplierBatchNo')" align="left" prop="lichn" min-width="160" />
                            <el-table-column :label="$t('inventoryManagement.supplierNo')" align="left" prop="supplierCode" min-width="120" :show-overflow-tooltip="true" />
                            <el-table-column :label="$t('inventoryManagement.maturity')" align="left" prop="maturity" min-width="80" :show-overflow-tooltip="true" />
                            <el-table-column :label="$t('inventoryManagement.materialNo')" align="left" prop="materialCode" :show-overflow-tooltip="true" />
                            <el-table-column :label="$t('inventoryManagement.materialName')" show-overflow-tooltip align="left" prop="materialName" />
                            <el-table-column :label="$t('inventoryManagement.materialType')" align="left" prop="materialType" min-width="140" :show-overflow-tooltip="true" />
                            <el-table-column :label="$t('inventoryManagement.factory')" align="left" prop="factoryName" min-width="140" :show-overflow-tooltip="true" />
                            <el-table-column :label="$t('inspectionManagement.sapBatch')" align="left" prop="lot" min-width="140" :show-overflow-tooltip="true" />

                            <el-table-column :label="$t('inspectionManagement.incomingQuantity')" align="left" prop="batchAmount" min-width="140" :show-overflow-tooltip="true" />
                            <el-table-column label="单位" align="left" fixed="right" prop="mengeneinh" min-width="100" :show-overflow-tooltip="true" />
                        </el-table>
                    </el-col>
                    <!-- <el-col :span="24">
                <el-form-item :label="$t('inventoryManagement.description')" prop="description" style="width:100%">
                    <el-input
                        type="textarea"
                        :autosize="{ minRows: 5, maxRows: 6}"
                        v-model="viewModel.description"
                        maxlength="1000"

                    >
                    </el-input>
                </el-form-item>
            </el-col> -->

                </el-row>

            </el-form>
        </el-card>

        <el-card class="box-card" style="margin-top:24px">
            <div class="container-header">
                <div class="hign-line"></div>
                <div class="header-left">
                    {{$t('inspectionManagement.comprehensiveJudgment')}}
                </div>
            </div>
            <el-form :model="viewModel" ref="queryForm" v-show="showSearch" label-width="110px" :rules="rules">
                <el-row :gutter="24" class="mb8">
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.destructiveMaterialInformation')" prop="destroyAmount">
                            <el-input v-model="viewModel.destroyAmount" clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.judgmentResult')" prop="decideResult">
                            <span v-if="viewModel.decideResult == '1'" class="result-tag-green">合格</span>
                            <span v-if="viewModel.decideResult == '0'" class="result-tag-red">不合格</span>
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item :label="$t('inventoryManagement.description')" prop="description" style="width:100%">
                            <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 6}" v-model="viewModel.description" maxlength="1000">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="审批人" prop="releaseApprover">
                            <select-user-dialog v-model="viewModel.releaseApprover" @callback="selectUserCB"/>
                        </el-form-item>
                    </el-col>

                </el-row>

            </el-form>
        </el-card>
        <div class="submit-footer">
            <el-button icon="el-icon-close" size="small" @click="closeTab" class="drawer-close">{{$t('public.close')}}</el-button>
            <el-button type="primary" @click="submitForm" icon="el-icon-check" size="small">{{$t('inspectionManagement.emergencyRelease')}}</el-button>
        </div>
        <template-dialog :visible.sync="templateVisible" />
    </div>

</template>

<script>
import {
    listType,
    getType,
    delType,
    addType,
    updateType,
    refreshCache,
} from '@/api/basic/dict/type'
import { getNoticeList, deleteNotice, readNotice } from '@/api/system/message'

import {
    getReleaseInfo,
    getRelease,
} from '@/api/inspectionManagement/inspectionManagement'
import FileUploadInput from '@/components/FileUploadInput'
import SupplierDialog from '@/views/components/SupplierDialog'
import MaterialDialog from '@/views/components/MaterialDialog'
import TemplateDialog from '@/views/components/TemplateDialog'
import MeasuringToolDialog from '@/views/components/MeasuringToolDialog'
import SelectUserDialog from '@/views/components/SelectUserDialog'
export default {
    name: 'inspectionExemption',
    dicts: ['sys_normal_disable'],
    components: {
        FileUploadInput,
        SupplierDialog,
        MaterialDialog,
        TemplateDialog,
        MeasuringToolDialog,
        SelectUserDialog,
    },
    data() {
        return {
            direction: 'rtl',
            passModel: [],
            addInspectionExemption: false,
            templateVisible: false,
            drawer: false,
            approvalOpen: false,
            viewInspectionExemption: false,
            inspectionOptions: [
                {
                    value: '1',
                    label: '检验项1',
                },
                {
                    value: '2',
                    label: '检验项2',
                },
            ],
            inspectionTypeUnitOptions: [
                {
                    value: '1',
                    label: '单位1',
                },
                {
                    value: '2',
                    label: '单位2',
                },
            ],
            frequencyOptions: [
                {
                    value: '1',
                    label: '批',
                },
                {
                    value: '2',
                    label: '件',
                },
                {
                    value: '3',
                    label: '年',
                },
                {
                    value: '4',
                    label: '季',
                },
                {
                    value: '5',
                    label: '月',
                },
            ],
            samplingSchemeOptions: [
                {
                    value: '1',
                    label: 'GB/T2828.1-2012',
                },
                {
                    value: '2',
                    label: '百分比',
                },
                {
                    value: '3',
                    label: '固定抽样',
                },
                {
                    value: '4',
                    label: 'C=0',
                },
            ],
            testMethodOptions: [
                {
                    value: '1',
                    label: '目测',
                },
                {
                    value: '2',
                    label: '量具',
                },
                {
                    value: '3',
                    label: '验证',
                },
            ],
            samplingLevelOptions: [
                {
                    value: '1',
                    label: 'S-1',
                },
                {
                    value: '2',
                    label: 'S-2',
                },
                {
                    value: '3',
                    label: 'S-3',
                },
                {
                    value: '4',
                    label: 'S-4',
                },
            ],
            samplingLevelTypeOptions: [
                {
                    value: '1',
                    label: '正常',
                },
                {
                    value: '2',
                    label: '放宽',
                },
                {
                    value: '3',
                    label: '加严',
                },
            ],
            samplingFixedTypeOptions: [
                {
                    value: '1',
                    label: '批',
                },
                {
                    value: '2',
                    label: '件',
                },
            ],
            specialCharacteristicsOptions: [
                {
                    value: '1',
                    label: 'CC',
                },
                {
                    value: '2',
                    label: 'SC',
                },
            ],
            addModel: {},
            viewModel: {
                lichn: '',
                lot: '',
                materialName: '',
                materialCode: '',
                maturity: '',
                supplierCode: '',
                batchAmount: '',
                mengeneinh: '',
                exempted: '',
                factoryName: '',
                amendMeng: '',
                amendBatch: '',
                outerPacking: '',
                inspectionRohs: '',
                inspectionCoa: '',
                destroyAmount: 0,
                description: undefined,
                decideResult: undefined,
            },
            editModel: {},
            approvalForm: {
                status: '1',
                textarea: '',
            },
            selBtn: 1,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                noticeTitle: undefined,
                noticeType: undefined,
                hasRead: undefined,
                createTime: undefined,
            },
            id: this.$route.params.id,
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                releaseApprover: [
                    {
                        required: true,
                        message: '审批人不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            fullscreen: false,
        }
    },
    created() {
        this.getList()
        this.getPassInfo()
    },
    methods: {
        getPassInfo() {
            getReleaseInfo({ ids: this.id }).then((response) => {
                this.passModel = response.data
                if(Array.isArray(response?.data)){
                    this.viewModel.decideResult = response?.data[0].decideResult
                }
                this.loading = false
            })
        },
        supplierDataCallback(row) {
            this.viewModel.supplierNo = row.supplierNo
            this.viewModel.supplierType = row.supplierType
        },
        materialDataCallback(row) {
            this.viewModel.materialNo = row.materialNo
            this.viewModel.materialType = row.materialType
            this.viewModel.maturity = row.maturity
            this.viewModel.materialTypeName = row.materialTypeName
        },
        closeTab() {
            this.$router.push({ path: '/inspect/incoming' })
        },
        effectDateChange(e, scope) {
            if (parseInt(e) > 0) {
                this.typeList[scope.$index].endDate = this.getNewDay(
                    scope.row.approvalTime,
                    e
                )
            }
        },
        getNewDay(dateTemp, days) {
            var dateTemp = dateTemp.split('-')
            //转换为MM-DD-YYYY格式
            var nDate = new Date(
                dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]
            )
            var millSeconds = Math.abs(nDate) + days * 24 * 60 * 60 * 1000
            var rDate = new Date(millSeconds)
            var year = rDate.getFullYear()
            var month = rDate.getMonth() + 1
            if (month < 10) month = '0' + month
            var date = rDate.getDate()
            if (date < 10) date = '0' + date
            return year + '-' + month + '-' + date
        },
        fileChange(e) {
            console.log(e)
        },
        drawerClose() {
            this.drawer = false
        },
        /** 查询字典类型列表 */
        getList() {
            this.loading = true
            this.typeList = [
                {
                    approvalTime: '2022-05-19',
                    endDate: '',
                    measuringTool: null,
                },
            ]
            getNoticeList(this.queryParams).then((response) => {
                if (response.code == 200 && response.rows) {
                    //   this.typeList = response.rows;
                    this.total = response.total
                    this.loading = false
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.typeList.push({})
        },
        handleSelectTemplate() {
            this.templateVisible = true
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.dictId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改字典类型'
            })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs['queryForm'].validate((valid) => {
                if (valid) {
                    let submitData = {
                        id: this.id,
                        description: this.viewModel.description,
                        destroyAmount: this.viewModel.destroyAmount,
                        decideResult:  this.viewModel.decideResult,
                        releaseApprover: this.viewModel.releaseApprover,
                        releaseApproverId: this.viewModel.releaseApproverId,
                    }
                    getRelease(submitData).then((response) => {
                        this.$modal.msgSuccess('提交成功!')
                        this.$router.push({ path: '/inspect/incoming' })
                    })
                } else {
                    console.log('error submit!!')
                    return false
                }
            })
        },
        /** 发起检验提交 */
        submitAddForm: function () {
            this.$modal.msgSuccess('发起成功!')
            this.addInspection = false
        },

        /** 删除按钮操作 */
        handleDelete(row) {
            if (this.typeList.length === 1) {
                this.$modal.msgWarning('请至少保留一条检验项!')
                return
            }
            this.typeList.splice(row.$index, 1)
        },
        /** 查看按钮操作 */
        handleView(row) {
            this.form = row
            this.viewInspectionExemption = true
            //   if(row.hasRead == 0){
            //     readNotice(row.noticeId).then(res=>{
            //       if(res.code == 200){
            //         this.handleQuery()
            //       }
            //     })
            //   }
        },
        /** 编辑按钮操作 */
        handleEdit(row) {
            this.drawer = true
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                'system/dict/type/export',
                {
                    ...this.queryParams,
                },
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
        selectUserCB(record){
            this.viewModel.releaseApproverId = record
        }
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
    padding-left: 12px;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
    max-height: calc(100vh - 600px);
    overflow: auto;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.hign-line {
    position: relative;
    left: -8px;
    top: 14px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #0b7be3;
    float: left;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
.submit-footer {
    height: 52px;
    background: #ffffff;
    box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px 4px 0px 0px;
    position: fixed;
    z-index: 9;
    bottom: 0px;
    width: 100%;
    left: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.samplingPercent {
    position: absolute;
    z-index: 9;
    right: 20px;
}
::v-deep .el-card {
    padding-top: 0px;
}
.app-detail {
    max-height: calc(100vh - 180px);
    overflow: auto;
}
.result-tag-red {
    width: 36px;
    height: 18px;
    font-size: 12px;
    font-weight: 400;
    color: #eb5648;
    background: rgba(235, 86, 72, 0.08);
    line-height: 18px;
    border-radius: 2px;
}
.result-tag-green {
    width: 40px;
    height: 20px;
    font-size: 12px;
    font-weight: 400;
    color: #20b09f;
    line-height: 18px;
    background: rgba(32, 176, 159, 0.08);
    border-radius: 2px;
}

.result-tag-yellow {
    width: 40px;
    height: 20px;
    font-size: 12px;
    font-weight: 400;
    color: #dbcd0c;
    line-height: 18px;
    background: rgba(236, 175, 7, 0.08);
    border-radius: 2px;
}
</style>
